package com.iflytek.crvoice2txt.util;

import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.iflytek.crvoice2txt.present.RecoderSignPresent;

public class Count60S {

    public int timelong;
    private CountDownTimer countDownTimer;
    private long TIMELONG = 60000;
    private RecoderSignPresent.OnVoiceDictationFinished onVoiceDictationFinished;

    public Count60S(RecoderSignPresent.OnVoiceDictationFinished onVoiceDictationFinished) {
        this.onVoiceDictationFinished = onVoiceDictationFinished;
        init();
    }

    private void init() {
        if (countDownTimer != null) {
            countDownTimer.cancel();
            countDownTimer = null;
        }
        timelong=0;
        countDownTimer = new CountDownTimer(TIMELONG, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                int sed = (int) millisUntilFinished / 1000;
                timelong=60-sed;
                Count60S.this.onVoiceDictationFinished.countDown(sed);
            }

            @Override
            public void onFinish() {
                this.cancel();
            }
        };
    }

    public void start() {
        if(countDownTimer==null){
            init();
        }
        countDownTimer.start();
    }

    public void stop() {
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
    }

}
